package com.crealth.manager;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.crealth.db.LoanContractDb;


public class LoanContractNoMgr {
	private static final int noBegin = 181;
	private static int curNo = noBegin;
	
	public static void initContractNo() {
		Integer maxNo = LoanContractDb.selectContractNoNum();
		if (maxNo != null) {
			curNo = maxNo + 1;
		}
		else {
			curNo = noBegin;
		}
	}
	
	public static String getLoanContractNo(int companyID, Timestamp applyTm) {
		String strNo = "";
		Date curDate = new Date(applyTm.getTime());
    	String simpleFmt = new SimpleDateFormat("yyyyMMdd").format(curDate);
		strNo = String.format("%s%02d%04d", simpleFmt, companyID, curNo);
		
		LoanContractDb.updateMaxContractNo(curNo);
		curNo++;
		return strNo;
	}

}
